%undefine _debugsource_packages
%define dont_relink 1

%define tarname sane-katusham247-1.19-alt1.x86_64
%define rel 220628
%define libver 1.0.27
%define pname katusham247

Summary(ru_RU.UTF-8):	Драйвера для сканера Катюша 247(e)
Summary:	Katusha 247(e) sane drivers
Name:		sane-%{pname}
Version:	1.19
Release:	%{rel}.3
License:	GPL
Group:		System/Configuration/Printing
Url:		https://katusha-it.ru/
Vendor:		Katusha
# https://disk.yandex.ru/d/4HMt9Ck2ScpTtA/Драйвера/Linux/Сканирование/RPM
Source0:	%{tarname}_%{rel}.tar.gz
BuildRequires:	%{_bindir}/rpm2cpio
BuildRequires:	tar
ExclusiveArch:	x86_64
Requires:	sane

%description
SANE drivers for Katusha 247(e).

%description -l ru_RU.UTF-8
Драйвера SANE для сканера Катюша 247(e).

%files
%{_libdir}/sane/libsane-%{pname}.so.%{libver}
%{_libdir}/sane/libsane-%{pname}.so.1
%{_libdir}/sane/libsane-%{pname}.so
%{_udevrulesdir}/65-%{pname}.rules
%{_sysconfdir}/sane.d/dll.d/%{pname}
%{_bindir}/%{pname}-scanner-ip-setup
%config(noreplace) %{_sysconfdir}/sane.d/%{pname}.conf

#------------------------------------------------------------------

%prep
%setup -n %{tarname}
rpm2cpio %{tarname}.rpm | cpio -idmv

%build

%install
mkdir -p %{buildroot}%{_bindir}
mkdir -p %{buildroot}%{_libdir}/sane
mkdir -p %{buildroot}%{_sysconfdir}/sane.d/dll.d
mkdir -p %{buildroot}%{_udevrulesdir}

install -m755 usr/lib64/sane/libsane-%{pname}.so.%{libver} %{buildroot}%{_libdir}/sane
pushd %{buildroot}%{_libdir}/sane
ln -s libsane-%{pname}.so.%{libver} libsane-%{pname}.so.1
ln -s libsane-%{pname}.so.%{libver} libsane-%{pname}.so
popd
install -m644 etc/udev/rules.d/65-scanner.rules %{buildroot}%{_udevrulesdir}/65-%{pname}.rules
echo "%{pname}" > %{buildroot}%{_sysconfdir}/sane.d/dll.d/%{pname}

# Поиск сканера по сети надо настраивать скриптом katusham247-scanner-ip-setup
install -m644 etc/sane.d/%{pname}.conf %{buildroot}%{_sysconfdir}/sane.d
install -m755 katusham247-scanner-ip-setup.sh %{buildroot}%{_bindir}/%{pname}-scanner-ip-setup
